<template>
  <avue-table-search
    v-model="searchParams"
    :option="searchOption"
    @search-change="loadTableSearch"
    @search-reset="loadTableSearchReset"
  >
    <template #menu-after>
      <!-- 其他按钮 -->
      <el-button>导出</el-button>
    </template>
  </avue-table-search>

  <avue-crud
    ref="crudRef"
    v-model="formData"
    :data="tableData"
    :option="tableOption"
    :page="page"
    :table-loading="tableLoading"
    @refresh-change="loadGetTableData"
    @current-change="loadTablePageChange"
    @size-change="loadTablePageSizeChange"
  >
    <template #smsSendStatus="{ row }">
      <span>{{ row.smsSendStatus }}</span>
    </template>
  </avue-crud>
</template>

<script setup>
  import Option from "@/crudOption/application/purchaseRecord";
  import useCrudHook from "avue-table/useCrudHook";
  import { useUserInfoStore } from "@/store/modules/userInfo";

  const { userInfo } = useUserInfoStore();

  // 配置
  const { searchOption, tableOption } = Option();
  let {
    data: tableData,
    loading: tableLoading,
    page,
    search: searchParams,
    form: formData,
    get: loadGetTableData,
    pageNumChange: loadTablePageChange,
    pageSizeChange: loadTablePageSizeChange,
    searchReset: loadTableSearchReset,
    searchChange: loadTableSearch,
  } = useCrudHook({
    // get: Api.application.operatorSpendSmsPage,
    // 搜索参数格式化
    getParamsFormat: p => {
      const params = { ...p };
      if (Array.isArray(params.execTime) && params.execTime.length === 2) {
        params.execBeginTime = params.execTime[0];
        params.execEndTime = params.execTime[1];
      }
      delete params.execTime;
      params.tenantId = userInfo.tenantId;
      params.serviceCategoryId = 4;
      return params;
    },
  });

  onMounted(async () => {
    await loadGetTableData();
  });
</script>
<style lang="scss" scoped></style>
